package com.example.a15787.weather_zyy_1235;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class NetworkUtils {
    public static String fetchWeatherData(String urlString) throws IOException{
        HttpURLConnection connection = (HttpURLConnection)new URL(urlString).openConnection();
        connection.setRequestMethod("GET");
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(connection.getInputStream()))){
            StringBuilder response = new StringBuilder();
            String line;
            while ((line = reader.readLine())!=null){
                response.append(line);
            }
            return response.toString();
        }finally {
            connection.disconnect();
        }
    }
}